package com.demo.key

import android.app.ActivityManager
import android.app.Application
import com.demo.key.pa.Home0822Pa
import com.demo.key.server.ServerInfo0822Manager
import com.demo.key.util.Activity0822Callback
import com.github.shadowsocks.Core
import com.google.android.gms.ads.MobileAds
import com.tencent.mmkv.MMKV

lateinit var mKey: Key
class Key:Application() {
    override fun onCreate() {
        super.onCreate()
        mKey=this
        Core.init(this,Home0822Pa::class)
        if (!packageName.equals(processName(this))){
            return
        }
        MobileAds.initialize(this)
        MMKV.initialize(this)
        Activity0822Callback.register(this)
        ServerInfo0822Manager.readLocalServerInfo()
        ServerInfo0822Manager.readFirebaseInfo()
    }

    private fun processName(applicationContext: Application): String {
        val pid = android.os.Process.myPid()
        var processName = ""
        val manager = applicationContext.getSystemService(Application.ACTIVITY_SERVICE) as ActivityManager
        for (process in manager.runningAppProcesses) {
            if (process.pid === pid) {
                processName = process.processName
            }
        }
        return processName
    }
}